package net.sxjr.protal.igpuoffice.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import net.sxjr.common.Response;
import net.sxjr.mbg.entity.IgCadreRecruitManage;
import net.sxjr.mbg.entity.IgImportantDecideManage;
import net.sxjr.mbg.entity.IgImportantProjectManage;
import net.sxjr.mbg.entity.IgLagerAmountCapitalManage;
import net.sxjr.mbg.mapper.IgCadreRecruitManageMapper;
import net.sxjr.mbg.mapper.IgImportantDecideManageMapper;
import net.sxjr.mbg.mapper.IgImportantProjectManageMapper;
import net.sxjr.mbg.mapper.IgLagerAmountCapitalManageMapper;
import net.sxjr.protal.igpuoffice.params.IgCadreRecruitManageParams;
import net.sxjr.protal.igpuoffice.params.IgImportantDecideManageParams;
import net.sxjr.protal.igpuoffice.params.IgImportantProjectManageParams;
import net.sxjr.protal.igpuoffice.params.IgLagerAmountCapitalManageParams;
import net.sxjr.protal.mapconverter.Converter;
import net.sxjr.protal.publicservice.PublicService;
import net.sxjr.protal.user.dao.LoginUserInfo;
import net.sxjr.protal.user.dao.UserInfo;
import net.sxjr.protal.user.service.LoginService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author ：cuixc
 * @date ：Created in 2020/12/14 14:23
 * @description：
 * @modified By：
 */
@Service
public class IgImportantService {
    @Autowired
    private LoginService loginService;
    @Autowired
    private PublicService publicService;
    @Autowired
    private IgImportantProjectManageMapper projectManageMapper;
    @Autowired
    private IgImportantDecideManageMapper decideManageMapper;
    @Autowired
    private IgCadreRecruitManageMapper cadreRecruitManageMapper;
    @Autowired
    private IgLagerAmountCapitalManageMapper amountCapitalManageMapper;
    public Response decideManage(IgImportantDecideManageParams params) {
        //获取当前登入人
        LoginUserInfo currentUser = loginService.getCurrentUser();
        UserInfo userinfo = loginService.getUserinfo(currentUser.getAccount());
        IgImportantDecideManage igImportantDecideManage = Converter.INSTANCE.importantDecideManageParams2Dao(params);
        if(StringUtils.isBlank(igImportantDecideManage.getImportantDecideManageId())){
            igImportantDecideManage.setCreateDate(new Date());
            igImportantDecideManage.setCreateOp(userinfo.getUserId());
            igImportantDecideManage.setDeptId(userinfo.getDeptId());
            igImportantDecideManage.insert();
        }else{
            igImportantDecideManage.updateById();

            publicService.setLinkConfirm(igImportantDecideManage,loginService.getCurrentUser());

        }
        publicService.writeSmsManage(publicService.getLinkCode(igImportantDecideManage),igImportantDecideManage.getSuperviseCode());

        return Response.success(Converter.INSTANCE.importantDecideManageDao2Params(igImportantDecideManage));
    }

    public Response projectmanage(IgImportantProjectManageParams params) {
        //获取当前登入人
        LoginUserInfo currentUser = loginService.getCurrentUser();
        UserInfo userinfo = loginService.getUserinfo(currentUser.getAccount());
        IgImportantProjectManage projectManage = Converter.INSTANCE.importantProjectManageParams2Dao(params);
        if(StringUtils.isBlank(projectManage.getImportantProjectManageId())){
            projectManage.setCreateDate(new Date());
            projectManage.setCreateOp(userinfo.getUserId());
            projectManage.setDeptId(userinfo.getDeptId());
            projectManage.insert();
        }else{
            projectManage.updateById();
            publicService.setLinkConfirm(projectManage,loginService.getCurrentUser());
        }
        publicService.writeSmsManage(publicService.getLinkCode(projectManage),projectManage.getSuperviseCode());

        return Response.success(Converter.INSTANCE.importantProjectManageDao2Params(projectManage));
    }

    public Response cadreRecruitManage(IgCadreRecruitManageParams params) {
        //获取当前登入人
        LoginUserInfo currentUser = loginService.getCurrentUser();
        UserInfo userinfo = loginService.getUserinfo(currentUser.getAccount());
        IgCadreRecruitManage igCadreRecruitManage = Converter.INSTANCE.cadreRecruitManageParams2Dao(params);
        if(StringUtils.isBlank(igCadreRecruitManage.getCadreRecruitManageId())){
            igCadreRecruitManage.setCreateDate(new Date());
            igCadreRecruitManage.setCreateOp(userinfo.getUserId());
            igCadreRecruitManage.setDeptId(userinfo.getDeptId());
            igCadreRecruitManage.insert();
        }else{
            igCadreRecruitManage.updateById();

            publicService.setLinkConfirm(igCadreRecruitManage,loginService.getCurrentUser());


        }
        publicService.writeSmsManage(publicService.getLinkCode(igCadreRecruitManage),igCadreRecruitManage.getSuperviseCode());

        return Response.success(Converter.INSTANCE.cadreRecruitManageDao2Params(igCadreRecruitManage));

    }
    //大额资金风控
    public Response lagerAmountCapitalManage(IgLagerAmountCapitalManageParams params) {
        //获取当前登入人
        LoginUserInfo currentUser = loginService.getCurrentUser();
        UserInfo userinfo = loginService.getUserinfo(currentUser.getAccount());
        IgLagerAmountCapitalManage amountCapitalManage = Converter.INSTANCE.lagerAmountCapitalManageParams2Dao(params);
        if(StringUtils.isBlank(amountCapitalManage.getLagerAmountCapitalManageId())){
            amountCapitalManage.setCreateDate(new Date());
            amountCapitalManage.setCreateOp(userinfo.getUserId());
            amountCapitalManage.setDeptId(userinfo.getDeptId());
            amountCapitalManage.insert();
        }else{
            amountCapitalManage.updateById();

            publicService.setLinkConfirm(amountCapitalManage,loginService.getCurrentUser());


        }
        publicService.writeSmsManage(publicService.getLinkCode(amountCapitalManage),amountCapitalManage.getSuperviseCode());

        return Response.success(Converter.INSTANCE.lagerAmountCapitalManageDao2Params(amountCapitalManage));
    }

    //重大项目列表
    public Response projectmanageList() {
        List<IgImportantProjectManage> projectManages = projectManageMapper.selectList(
                new LambdaQueryWrapper<IgImportantProjectManage>().ne(IgImportantProjectManage::getDeleteFlag,1)
                        .or().isNull(IgImportantProjectManage::getDeleteFlag)
                        .orderByDesc(IgImportantProjectManage::getCreateDate));

        return Response.success(Converter.INSTANCE.importantProjectManageDao2Params(projectManages));
    }
    //重大项目风控
    public Response decideManageList() {
        List<IgImportantDecideManage> decideManages = decideManageMapper.selectList(
                new LambdaQueryWrapper<IgImportantDecideManage>().ne(IgImportantDecideManage::getDeleteFlag,1)
                        .or().isNull(IgImportantDecideManage::getDeleteFlag)
                        .orderByDesc(IgImportantDecideManage::getSuperviseCode));
        return Response.success(Converter.INSTANCE.importantDecideManageDao2Params(decideManages));

    }
    //干部聘用
    public Response cadreRrecruitmanageList() {
        List<IgCadreRecruitManage> recruitManages = cadreRecruitManageMapper.selectList(
                new LambdaQueryWrapper<IgCadreRecruitManage>().ne(IgCadreRecruitManage::getDeleteFlag,1)
                        .or().isNull(IgCadreRecruitManage::getDeleteFlag)
                        .orderByDesc(IgCadreRecruitManage::getSuperviseCode));
        return Response.success(Converter.INSTANCE.cadreRecruitManageDao2Params(recruitManages));
    }

    //大额资金风控
    public Response lagerAmountCapitalManageList() {
        List<IgLagerAmountCapitalManage> igLagerAmountCapitalManages = amountCapitalManageMapper.selectList(
                new LambdaQueryWrapper<IgLagerAmountCapitalManage>().ne(IgLagerAmountCapitalManage::getDeleteFlag,1)
                        .or().isNull(IgLagerAmountCapitalManage::getDeleteFlag)
                        .orderByDesc(IgLagerAmountCapitalManage::getSuperviseCode));
        return Response.success(Converter.INSTANCE.lagerAmountCapitalManageDao2Params(igLagerAmountCapitalManages));
    }


}
